package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CouponUsedInfo;
import com.ruoyi.system.service.ICouponUsedInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 优惠券使用情况Controller
 * 
 * @author ruoyi
 * @date 2024-01-04
 */
@RestController
@RequestMapping("/system/coupon_used")
public class CouponUsedInfoController extends BaseController
{
    @Autowired
    private ICouponUsedInfoService couponUsedInfoService;

    /**
     * 查询优惠券使用情况列表
     */
    @PreAuthorize("@ss.hasPermi('system:coupon_used:list')")
    @GetMapping("/list")
    public TableDataInfo list(CouponUsedInfo couponUsedInfo)
    {
        startPage();
        List<CouponUsedInfo> list = couponUsedInfoService.selectCouponUsedInfoList(couponUsedInfo);
        return getDataTable(list);
    }

    /**
     * 导出优惠券使用情况列表
     */
    @PreAuthorize("@ss.hasPermi('system:coupon_used:export')")
    @Log(title = "优惠券使用情况", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CouponUsedInfo couponUsedInfo)
    {
        List<CouponUsedInfo> list = couponUsedInfoService.selectCouponUsedInfoList(couponUsedInfo);
        ExcelUtil<CouponUsedInfo> util = new ExcelUtil<CouponUsedInfo>(CouponUsedInfo.class);
        util.exportExcel(response, list, "优惠券使用情况数据");
    }

    /**
     * 获取优惠券使用情况详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:coupon_used:query')")
    @GetMapping(value = "/{receiveId}")
    public AjaxResult getInfo(@PathVariable("receiveId") Long receiveId)
    {
        return success(couponUsedInfoService.selectCouponUsedInfoByReceiveId(receiveId));
    }

    /**
     * 新增优惠券使用情况
     */
    @PreAuthorize("@ss.hasPermi('system:coupon_used:add')")
    @Log(title = "优惠券使用情况", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CouponUsedInfo couponUsedInfo)
    {
        return toAjax(couponUsedInfoService.insertCouponUsedInfo(couponUsedInfo));
    }

    /**
     * 修改优惠券使用情况
     */
    @PreAuthorize("@ss.hasPermi('system:coupon_used:edit')")
    @Log(title = "优惠券使用情况", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CouponUsedInfo couponUsedInfo)
    {
        return toAjax(couponUsedInfoService.updateCouponUsedInfo(couponUsedInfo));
    }

    /**
     * 删除优惠券使用情况
     */
    @PreAuthorize("@ss.hasPermi('system:coupon_used:remove')")
    @Log(title = "优惠券使用情况", businessType = BusinessType.DELETE)
	@DeleteMapping("/{receiveIds}")
    public AjaxResult remove(@PathVariable Long[] receiveIds)
    {
        return toAjax(couponUsedInfoService.deleteCouponUsedInfoByReceiveIds(receiveIds));
    }
}
